<template>
  <div>
    <el-button :loading="loading" type="primary" @click="login">登录</el-button>
    <el-button type="success" @click="getInfo()">请求数据</el-button>
  </div>
</template>

<script>
import {getInfo, login} from "@/api/user";
import {setToken} from "@/utils/auth";

export default {
  name: "index",
  data() {
    return {
      loading: false,
    }
  },
  methods: {
    login() {
      console.log("login")
      this.loading = true
      login({
        userNo: "12138",
        pwd: "12138",
      }).then(resp => {
        if (resp.status == 200) {
          let body = resp.body;
          setToken(body.access_token, body.refresh_token);
          this.loading = false
        }
      }).catch((error) => {
        console.error(error)
        this.loading = false
      })
    },
    getInfo() {
      //todo 并发请求，没有阻塞住
      getInfo().then(resp => {
        console.log("getInfo resp:", JSON.stringify(resp));
      }).catch(error => {
        console.error("请求失败:", error)
      });
    }
  }
}
</script>

<style scoped>

</style>
